import { auditManageConst } from "src/consts/audit_manage_const";
import { PopupName } from "src/consts/popup_const";
import * as Api from 'src/api/net';

const state: any = {} as any;
// StateIniter.init(state, 'demo');

state.account = {};
state.website = {}
state.web_id = ""
state.reason = ""
state.purpose = ""
state.period_date = ""
state.owner_type = ""
state.owner_id = ""
state.dept = ""
state.create_date = ""
state.audit_status = ""
state.url = ""
state.name = ""
state.apply_name = ""
// vuex

/** 更新数据的 */
const mutations = {
    [auditManageConst.CommitAuditMShow](state: any, data: any): void {
        console.log("AuditM_Panel data update", data);
        state.account = data.account
        state.website = data.website
        if (data.account) {
            state.apply_name = data.account.name
        } else {
            state.apply_name = data.apply_name
        }

        if (data.website) {
            state.url = data.website.url
            state.name = data.website.name
        } else {
            state.url = data.url
            state.name = data.name
        }

        state.web_id = data.web_id
        state.reason = data.reason
        state.purpose = data.purpose
        state.period_date = data.period_date
        state.owner_type = data.owner_type
        state.owner_id = data.owner_id
        state.dept = data.dept
        state.create_date = data.create_date
        state.audit_status = data.audit_status
        WLLib.panel(PopupName.AuditM_Panel);
    }
}

//异步处理
const actions = {
    [auditManageConst.DispatchAuditMShow](context: VuexData, data?: any): void {
        var reqUrl = ""
        var sendData: any = {}

        if (data.model == "wanzhan_website") {
            reqUrl = "/website/show.do"
            sendData.id = data.entity_id
        } else if (data.model == "wanzhan_apply") {
            reqUrl = "/webapply/all/show.do"
            sendData.id = data.entity_id
        }
        Api.AjaxPost(Config.ajaxUrl + reqUrl, sendData, (res: any) => {
            if (isNoEmptyObject(res.data)) {
                WLCommit(auditManageConst.CommitAuditMShow, res.data);
            }
        })
    }
}

export default {
    state,
    mutations,
    actions
}